package com.longqinuo.mycarservice.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;


import com.longqinuo.mycarservice.R;

import java.util.List;

/**
 * 自定义默认排序适配器
 * Created by zxw on 2016/6/8.
 */
public class PriceAgeAdapter extends BaseAdapter {
    private Context context;
    private List<String> mList;
    private static int mPricePosition = 0;
    private static int mMileagePosition = 0;
    private static int mAgePosition = 0;
    public PriceAgeAdapter(Context context, List<String> list) {
        // TODO Auto-generated constructor stub
        this.context = context;
        this.mList = list;
    }
    @Override
    public int getCount() {
        // TODO Auto-generated method stub
        return mList.size();
    }

    @Override
    public Object getItem(int arg0) {
        // TODO Auto-generated method stub
        return mList.get(arg0);
    }

    @Override
    public long getItemId(int arg0) {
        // TODO Auto-generated method stub
        return arg0;
    }
    public void selectPricePosition(int pos) {
        this.mPricePosition = pos;
    }
    public void selectMileagePosition(int pos) {
        this.mMileagePosition = pos;
    }
    public void selectAgePosition(int pos) {
        this.mAgePosition = pos;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.price_mileage_age_item, null);
            holder = new ViewHolder(convertView);

            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        holder.text.setText(mList.get(position));
        switch (parent.getId()) {
            case R.id.gv_car_price_second:
                if (position==mPricePosition) {
                    holder.text.setSelected(true);
                } else {
                    holder.text.setSelected(false);
                }
                break;
            case R.id.gv_car_mileage_second:
                if (position==mMileagePosition) {
                    holder.text.setSelected(true);
                } else {
                    holder.text.setSelected(false);
                }
                break;
            case R.id.gv_car_age_second:
                if (position==mAgePosition) {
                    holder.text.setSelected(true);
                } else {
                    holder.text.setSelected(false);
                }
                break;
        }


        return convertView;
    }

    public class ViewHolder{
        public ViewHolder(View itemView) {
            this.text = (TextView) itemView.findViewById(R.id.tv_price_item);
        }

        private TextView text;
    }
}
